#!/usr/local/bin/python3
__author__ = '曹植'

import requests
import time


def get_ip():
    url = 'http://h.wandouip.com/get/ip-list'
    params = {
        'app_key': '6ae37e47bae8366e220eaba8deee13af',
        'num': '1',
        'type': '2',
        'xy': '2',
        'lb': '\n',
        'mr': '3'
    }
    response = requests.get(url, params=params)
    result = response.json()['data'][0]
    expire_time = int(time.mktime(time.strptime(result['expire_time'], "%Y-%m-%d %H:%M:%S")))
    current_time = time.time()
    if expire_time < current_time:
        get_ip()
    proxy = 'http://{}:{}'.format(result['ip'], result['port'])
    return proxy